home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / commands / elvis / vi.c < prev    next >
C/C++ Source or Header  |  1990-07-15  |  19KB  |  677 lines

  1. /* vi.c */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    16820 SW Tallac Way
  6.  *    Beaverton, OR 97006
  7.  *    kirkenda@jove.cs.pdx.edu, or ...uunet!tektronix!psueea!jove!kirkenda
  8.  */
  9.  
  10.  
  11. #include <ctype.h>
  12. #include "vi.h"
  13.  
  14.  
  15.  
  16. /* This array describes what each key does */
  17. #define NO_FUNC        (MARK (*)())0
  18. #define NO_ARGS        0
  19. #define CURSOR_COUNT    1
  20. #define CURSOR        2
  21. #define CURSOR_CNT_KEY    3
  22. #define CURSOR_MOVED    4
  23. #define CURSOR_EOL    5
  24. #define ZERO        6
  25. #define DIGIT        7
  26. #define CURSOR_TEXT    8
  27. #define CURSOR_CNT_CMD    9
  28. #define KEYWORD        10
  29. #define NO_FLAGS    0x00
  30. #define    MVMT        0x01    /* this is a movement command */
  31. #define PTMV        0x02    /* this can be *part* of a movement command */
  32. #define FRNT        0x04    /* after move, go to front of line */
  33. #define INCL        0x08    /* include last char when used with c/d/y */
  34. #define LNMD        0x10    /* use line mode of c/d/y */
  35. #define NCOL        0x20    /* this command can't change the column# */
  36. #define NREL        0x40    /* this is "non-relative" -- set the '' mark */
  37. #define SDOT        0x80    /* set the "dot" variables, for the "." cmd */
  38. static struct keystru
  39. {
  40.     MARK    (*func)();    /* the function to run */
  41.     char    args;        /* description of the args needed */
  42.     char    flags;        /* other stuff */
  43. }
  44.     vikeys[] =
  45. {
  46. /* NUL not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  47. /* ^A  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  48. /* ^B  page backward    */    {movescroll,    CURSOR_CNT_CMD,    FRNT},
  49. /* ^C  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  50. /* ^D  scroll dn 1/2page*/    {movescroll,    CURSOR_CNT_CMD,    NCOL},
  51. /* ^E  scroll up    */    {movescroll,    CURSOR_CNT_CMD,    NCOL},
  52. /* ^F  page forward    */    {movescroll,    CURSOR_CNT_CMD,    FRNT},
  53. /* ^G  show file status    */    {v_status,    NO_ARGS,     NO_FLAGS},
  54. /* ^H  move left, like h*/    {moveleft,    CURSOR_COUNT,    MVMT},
  55. /* ^I  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  56. /* ^J  move down    */    {movedown,    CURSOR_COUNT,    MVMT|LNMD},
  57. /* ^K  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  58. /* ^L  redraw screen    */    {v_redraw,    NO_ARGS,    NO_FLAGS},
  59. /* ^M  mv front next ln */    {movedown,    CURSOR_COUNT,    MVMT|FRNT|LNMD},
  60. /* ^N  move down    */    {movedown,    CURSOR_COUNT,    MVMT|LNMD},
  61. /* ^O  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  62. /* ^P  not defined    */    {moveup,    CURSOR_COUNT,    MVMT|LNMD},
  63. /* ^Q  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  64. /* ^R  redraw screen    */    {v_redraw,    NO_ARGS,    NO_FLAGS},
  65. /* ^S  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  66. /* ^T  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  67. /* ^U  scroll up 1/2page*/    {movescroll,    CURSOR_CNT_CMD,    NCOL},
  68. /* ^V  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  69. /* ^W  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  70. /* ^X  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  71. /* ^Y  scroll down    */    {movescroll,    CURSOR_CNT_CMD,    NCOL},
  72. /* ^Z  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  73. /* ESC not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  74. /* ^\  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  75. /* ^]  keyword is tag    */    {v_tag,        KEYWORD,    NO_FLAGS},
  76. /* ^^  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  77. /* ^_  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  78. /* SPC move right,like l*/    {moveright,    CURSOR_COUNT,    MVMT},
  79. /*  !  run thru filter    */    {v_filter,    CURSOR_MOVED,    NO_FLAGS},
  80. /*  "  select cut buffer*/    {v_selcut,    CURSOR_CNT_KEY,    PTMV},
  81. #ifndef NO_EXTENSIONS
  82. /*  #  increment number    */    {v_increment,    KEYWORD,    SDOT},
  83. #else
  84. /*  #  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  85. #endif
  86. /*  $  move to rear    */    {moverear,    CURSOR,        MVMT|INCL},
  87. /*  %  move to match    */    {movematch,    CURSOR,        MVMT|INCL},
  88. /*  &  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  89. /*  '  move to a mark    */    {movetomark,    CURSOR_CNT_KEY,    MVMT|FRNT|NREL|LNMD},
  90. #ifndef NO_SENTENCE
  91. /*  (  mv back sentence    */    {movebsentence,    CURSOR_COUNT,    MVMT},
  92. /*  )  mv fwd sentence    */    {movefsentence,    CURSOR_COUNT,    MVMT},
  93. #else
  94. /*  (  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  95. /*  )  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  96. #endif
  97. /*  *  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  98. /*  +  mv front next ln */    {movedown,    CURSOR_COUNT,    MVMT|FRNT|LNMD},
  99. #ifndef NO_CHARSEARCH
  100. /*  ,  reverse [fFtT] cmd*/    {move_ch,    CURSOR_CNT_CMD,    MVMT|INCL},
  101. #else
  102. /*  ,  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  103. #endif
  104. /*  -  mv front prev ln    */    {moveup,    CURSOR_COUNT,    MVMT|FRNT|LNMD},
  105. /*  .  special...    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  106. /*  /  forward search    */    {movefsrch,    CURSOR_TEXT,    MVMT|NREL},
  107. /*  0  part of count?    */    {NO_FUNC,    ZERO,        MVMT|PTMV},
  108. /*  1  part of count    */    {NO_FUNC,    DIGIT,        PTMV},
  109. /*  2  part of count    */    {NO_FUNC,    DIGIT,        PTMV},
  110. /*  3  part of count    */    {NO_FUNC,    DIGIT,        PTMV},
  111. /*  4  part of count    */    {NO_FUNC,    DIGIT,        PTMV},
  112. /*  5  part of count    */    {NO_FUNC,    DIGIT,        PTMV},
  113. /*  6  part of count    */    {NO_FUNC,    DIGIT,        PTMV},
  114. /*  7  part of count    */    {NO_FUNC,    DIGIT,        PTMV},
  115. /*  8  part of count    */    {NO_FUNC,    DIGIT,        PTMV},
  116. /*  9  part of count    */    {NO_FUNC,    DIGIT,        PTMV},
  117. /*  :  run single EX cmd*/    {v_1ex,        CURSOR_TEXT,    NO_FLAGS},
  118. #ifndef NO_CHARSEARCH
  119. /*  ;  repeat [fFtT] cmd*/    {move_ch,    CURSOR_CNT_CMD,    MVMT|INCL},
  120. #else
  121. /*  ;  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  122. #endif
  123. /*  <  shift text left    */    {v_shiftl,    CURSOR_MOVED,    SDOT|FRNT},
  124. /*  =  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  125. /*  >  shift text right    */    {v_shiftr,    CURSOR_MOVED,    SDOT|FRNT},
  126. /*  ?  backward search    */    {movebsrch,    CURSOR_TEXT,    MVMT|NREL},
  127. /*  @  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  128. /*  A  append at EOL    */    {v_insert,    CURSOR_CNT_CMD,    SDOT},
  129. /*  B  move back Word    */    {movebWord,    CURSOR_COUNT,    MVMT},
  130. /*  C  change to EOL    */    {v_change,    CURSOR_EOL,    SDOT},
  131. /*  D  delete to EOL    */    {v_delete,    CURSOR_EOL,    SDOT},
  132. /*  E  move end of Word    */    {moveeWord,    CURSOR_COUNT,    MVMT|INCL},
  133. #ifndef NO_CHARSEARCH
  134. /*  F  move bk to char    */    {moveFch,    CURSOR_CNT_KEY,    MVMT|INCL},
  135. #else
  136. /*  F  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  137. #endif
  138. /*  G  move to line #    */    {movetoline,    CURSOR_COUNT,    MVMT|NREL|LNMD},
  139. /*  H  move to row    */    {moverow,    CURSOR_CNT_CMD,    FRNT},
  140. /*  I  insert at front    */    {v_insert,    CURSOR_CNT_CMD,    SDOT},
  141. /*  J  join lines    */    {v_join,    CURSOR_COUNT,    SDOT},
  142. #ifndef NO_EXTENSIONS
  143. /*  K  look up keyword    */    {v_keyword,    KEYWORD,    NO_FLAGS},
  144. #else
  145. /*  K  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  146. #endif
  147. /*  L  move to last row    */    {moverow,    CURSOR_CNT_CMD,    FRNT},
  148. /*  M  move to mid row    */    {moverow,    CURSOR_CNT_CMD,    FRNT},
  149. /*  N  reverse prev srch*/    {moveNsrch,    CURSOR,        MVMT},
  150. /*  O  insert above line*/    {v_insert,    CURSOR_CNT_CMD,    SDOT},
  151. /*  P  paste before    */    {v_paste,    CURSOR_CNT_CMD,    NO_FLAGS},
  152. /*  Q  quit to EX mode    */    {v_quit,    NO_ARGS,    NO_FLAGS},
  153. /*  R  overtype        */    {v_overtype,    CURSOR,        SDOT},
  154. /*  S  change line    */    {v_change,    CURSOR_MOVED,    SDOT},
  155. #ifndef NO_CHARSEARCH
  156. /*  T  move bk to char    */    {moveTch,    CURSOR_CNT_KEY,    MVMT|INCL},
  157. #else
  158. /*  T  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  159. #endif
  160. /*  U  undo whole line    */    {v_undoline,    CURSOR,        FRNT},
  161. /*  V  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  162. /*  W  move forward Word*/    {movefWord,    CURSOR_COUNT,    MVMT},
  163. /*  X  delete to left    */    {v_Xchar,    CURSOR_COUNT,    SDOT},
  164. /*  Y  yank text    */    {v_yank,    CURSOR_MOVED,    NO_FLAGS},
  165. /*  Z  save file & exit    */    {v_xit,        CURSOR_CNT_KEY,    NO_FLAGS},
  166. /*  [  move back section*/    {movebsection,    CURSOR_CNT_KEY,    MVMT|LNMD|NREL},
  167. /*  \  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  168. /*  ]  move fwd section */    {movefsection,    CURSOR_CNT_KEY,    MVMT|LNMD|NREL},
  169. /*  ^  move to front    */    {movefront,    CURSOR,        MVMT},
  170. /*  _  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  171. /*  `  move to mark    */    {movetomark,    CURSOR_CNT_KEY,    MVMT|NREL},
  172. /*  a  append at cursor    */    {v_insert,    CURSOR_CNT_CMD,    SDOT},
  173. /*  b  move back word    */    {movebword,    CURSOR_COUNT,    MVMT},
  174. /*  c  change text    */    {v_change,    CURSOR_MOVED,    SDOT},
  175. /*  d  delete op    */    {v_delete,    CURSOR_MOVED,    SDOT},
  176. /*  e  move end word    */    {moveeword,    CURSOR_COUNT,    MVMT|INCL},
  177. #ifndef NO_CHARSEARCH
  178. /*  f  move fwd for char*/    {movefch,    CURSOR_CNT_KEY,    MVMT|INCL},
  179. #else
  180. /*  f  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  181. #endif
  182. /*  g  not defined    */    {NO_FUNC,    NO_ARGS,    NO_FLAGS},
  183. /*  h  move left    */    {moveleft,    CURSOR_COUNT,    MVMT},
  184. /*  i  insert at cursor    */    {v_insert,    CURSOR_CNT_CMD,    SDOT},
  185. /*  j  move down    */    {movedown,    CURSOR_COUNT,    MVMT|NCOL|LNMD},
  186. /*  k  move up        */    {moveup,    CURSOR_COUNT,    MVMT|NCOL|LNMD},
  187. /*  l  move right    */    {moveright,    CURSOR_COUNT,    MVMT},
  188. /*  m  define a mark    */    {v_mark,    CURSOR_CNT_KEY